package engine.network
{
	public class RxNetMessageDistributor
	{
		private var m_inboundListeners:Object;
		
		public function RxNetMessageDistributor()
		{
			this.m_inboundListeners = new Object();
		}
		
		public function Distribute(message:RxNetMessageBase) : void
		{
			var fun:Function = null;
			var listeners:* = this.m_inboundListeners[message.GetId()];
			if (listeners != null)
			{
				for each (fun in listeners)
				{
					
					fun(message);
				}
			}
		}
		
		public function AddListener(key:uint, fun:Function) : void
		{
			var listeners:* = this.m_inboundListeners[key];
			if (listeners == null)
			{
				listeners = new Vector.<Function>;
				this.m_inboundListeners[key] = listeners;
			}
			
			listeners.push(fun);
		}
		
		public function RemoveListener(param1:uint, param2:Function) : void
		{
			var _loc_4:int = 0;
			var _loc_3:* = this.m_inboundListeners[param1];
			if (_loc_3 != null)
			{
				_loc_4 = _loc_3.indexOf(param2);
				if (_loc_4 >= 0)
				{
					if (_loc_3.length > 1)
					{
						_loc_3.splice(_loc_4, 1);
					}
					else
					{
						delete this.m_inboundListeners[param1];
					}
				}
			}
		}
		
		public function ClearListeners() : void
		{
			this.m_inboundListeners = new Object();
		}
	}
}